<?php
// +----------------------------------------------------------------------
// | ZGUAN [ 致力于帮助更多的中小企业物联网转型 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.zguan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ZGUAN 并不是自由软件，未经许可不能去掉ZGUAN 相关版权
// +----------------------------------------------------------------------
// | Author: ZGUAN Team <admin@zguan.cn>  0769-82282996  15899929162
// +----------------------------------------------------------------------
use think\facade\Route;

$propertyApiRoute = function () {
    // 公共接口应用独立域名时有用
    Route::group('', function () {
        if (env('MULTI_DOMAIN_MODE', false)) {
            foreach (config('common_route') as $routeFn) {
                $routeFn();
            }
        }
    })->prefix('');

    Route::group('common', function () {


    });

    Route::group('property', function () {
        Route::group('article', function () {
            Route::group('news', function () {
                Route::get('getCate', '/getCate');
                Route::get('getNewsList', '/getNewsList');
                Route::get('getDetail/:id', '/getDetail');
            })->prefix('api.article.ArticleNews');## 新闻资询
            Route::group('guide', function () {
                Route::get('getCate', '/getCate');
                Route::get('getGuideList', '/guideList');
                Route::get('getDetail/:id', '/getDetail');
            })->prefix('api.article.ArticleGuide');## 操作指南
            Route::group('faq', function () {
                Route::get('getCate', '/getCate');
                Route::get('getFaqList', '/getFaqList');
                Route::get('getDetail/:id', '/getDetail');
            })->prefix('api.article.ArticleFaq');## 常见问题
        });

        # 公告信息 add
        Route::group('system', function () {
            Route::group('affiche', function () {
                Route::get('getCate', '/getCate');
                Route::get('getTopAfficheList', '/topAfficheList');
                Route::get('getAfficheList', '/afficheList');
                Route::get('getAfficheDetail/:id', '/afficheDetail');
            })->prefix('api.system.SystemAffiche');
        });
        # 公告信息 end
        # 公共信息
        Route::group('common', function () {
            Route::group('code', function () {
                Route::get('createVerifyCode', '/createVerifyCode');# 生成图形验证码
                Route::post('sendPhoneVerifyCode', '/sendPhoneVerifyCode'); #发送手机验证码
            })->prefix('api.common.Code');
            Route::group('config', function () {
                Route::get('getSmsConfig', '/getSmsConfig');# 获取短信配置
                Route::get('getPactInfo', '/getPactInfo');# 获取平台协议
                Route::get('getItemsInfo', '/getItemsInfo');# 获取项目信息
            })->prefix('api.common.Config');
            Route::group('upload', function () {
                Route::post('uploadImageAdd', '/uploadImageAdd');## 上传图片文件
            })->prefix('api.common.UploadFile');
            Route::group('property', function () {
                Route::get('getCateList', '/cateList');##获取物业类型
                Route::get('getLabelList', '/labelList');##获取物业标签
            })->prefix('api.common.PropertyCommon');
            Route::group('room', function () {
                Route::get('getLabelList', '/labelList');##获取房间标签
            })->prefix('api.common.RoomCommon');
            Route::group('housing', function () {
                Route::get('getLabelList', '/labelList');##获取房源标签
            })->prefix('api.common.HousingCommon');
            Route::group('repair', function () {
                Route::get('getCateList', '/cateList');##获取工单类型
            })->prefix('api.common.RepairCommon');
        });
        Route::group('login', function () {
            Route::post('passwordLogin', '/passwordLogin');## 密码登陆
            Route::post('mobileSmsLogin', '/mobileSmsLogin');## 短信验证码登录
        })->prefix('api.Login');

        ## 能耗管理 ADD
        Route::group('energy', function () {
            Route::group('meter', function () {
                Route::get('getList', '/list');##
                Route::get('getCodeMeter', '/getCodeMeter');## 根据二维码查询
                Route::get('getShareMeterUrl/:id', '/getShareMeterUrl');## 获取分享二维码
                Route::post('addBatch', '/addBatch');## 批量添加设备
                Route::post('codeAdd', '/codeAdd');## 扫码添加设备
                Route::put('edit/:id', '/edit');## 编辑设备
                Route::get('detail/:id', '/detail');##
                Route::delete('delete/:id', '/delete');##
                Route::post('switchPlanType/:id', '/switchPlanType');## 人工抄读设备
                Route::post('meterReading/:id', '/meterReading');## 人工抄读设备
                Route::post('autoReadCopy/:id', '/autoReadCopy');## 实时抄读设备
                Route::post('onEnergyMeter/:id', '/onEnergyMeter');## 合阀
                Route::post('offEnergyMeter/:id', '/offEnergyMeter');## 断阀
                Route::post('updateOnOff/:id', '/updateOnOff');## 更新
                Route::get('queryOperateResult', '/queryOperateResult');## 任务结果回调
                Route::get('dayMeterList', '/dayMeterList');## 日用量统计
                Route::get('getMeterLog', '/getMeterLog');## 设备日志
                Route::get('getOperateLog', '/getOperateLog');## 设备操作记录
                Route::get('getBalanceLog', '/getBalanceLog');## 余额变动日志
                Route::post('rechargePay/:id', '/rechargePay');## 余额充值
                Route::post('modifyBeilv/:id', '/modifyBeilv');## 倍率更新
                Route::post('makeOver/:id', '/makeOver');## 所有权转让
                Route::post('switchChargePrice/:id', '/switchChargePrice');## 收费方案更新
            })->prefix('api.energy.EnergyMeter'); ## 水电设备
            Route::group('users', function () {
                Route::post('userAdd/:id', '/userAdd');## 绑定新用户
                Route::get('getUsersList/:id', '/usersList');## 获取关联用户
                Route::delete('delete/:id', '/delete');##
            })->prefix('api.energy.EnergyUsers'); ## 关联用户列表
            Route::group('plan', function () {
                Route::get('getList', '/list');##
                Route::get('getListData', '/listData');##
                Route::post('add', '/add');##
                Route::put('edit/:id', '/edit');## 编辑
                Route::get('detail/:id', '/detail');##
                Route::get('detail/:id', '/detail');##
                Route::delete('delete/:id', '/delete');##
            })->prefix('api.energy.EnergyPlan'); ## 计费方案
            Route::group('shared', function () {
                Route::get('getList', '/list');##
                Route::post('add', '/add');##
                Route::put('edit/:id', '/edit');## 编辑
                Route::get('detail/:id', '/detail');##
                Route::delete('delete/:id', '/delete');##
                Route::group('room', function () {
                    Route::get('getList', '/list');##
                    Route::post('add', '/add');##
                    Route::put('edit/:id', '/edit');## 编辑
                    Route::delete('delete/:id', '/delete');##
                    Route::get('getRoomList/:id', '/roomList');## 未绑定房间列表
                    Route::get('getRoomLogs/:id', '/roomLogs');## 房间分摊日志
                })->prefix('api.energy.EnergySharedRoom'); ## 计费方案
            })->prefix('api.energy.EnergySharedPlan'); ## 计费方案
        })->middleware(\app\http\middleware\api\CheckToken::class, true);

        ## 能耗管理 END

        ## 物业管理 ADD
        Route::group('property', function () {
            Route::group('basic', function () {
                Route::get('getPropertyList', '/propertyList');##获取物业列表
                Route::group('', function () {
                    ## 根据管理员权限获取管理权限下物业
                    Route::get('getAllPropertyList', '/allPropertyList');
                    Route::get('getCode', '/getCode');## 获取物业编码
                    Route::post('addProperty', '/addProperty');## 添加物业
                    Route::put('editProperty/:id', '/editProperty');## 编辑物业
                    Route::delete('delProperty/:id', '/delProperty');## 删除物业
                    Route::get('detail/:id', '/detail');#### 物业详情
                    Route::get('getPropertySurvey/:id', '/getPropertySurvey');#### 物业概况
                })->middleware(\app\http\middleware\api\CheckToken::class, true);
            })->prefix('api.property.PropertyBasic'); ## 物业管理
            Route::group('unit', function () {
                Route::get('getUnitList/:id', '/unitList');
                Route::get('getTopUnit/:id', '/topUnitList');
                Route::post('add', '/add');
                Route::put('edit/:id', '/edit');
                Route::delete('delete/:id', '/delete');
            })->prefix('api.property.PropertyUnit')->middleware(\app\http\middleware\api\CheckToken::class, true); ## 楼栋单元
            Route::group('facility', function () {
                Route::get('getList', '/list');
                Route::post('add', '/add');
                Route::put('edit/:id', '/edit');
                Route::delete('delete/:id', '/delete');
            })->prefix('api.property.PropertyFacility')->middleware(\app\http\middleware\api\CheckToken::class, true); ## 物业设施
        });

        ## 物业管理 END
        ## 企业管理 ADD
        Route::group('firm', function () {
            Route::group('basic', function () {
                Route::get('getList', '/list');
                Route::post('add', '/add');
                Route::put('edit/:id', '/edit');
                Route::delete('delete/:id', '/delete');
            })->prefix('api.firm.FirmBasic')->middleware(\app\http\middleware\api\CheckToken::class, true); ## 楼栋单元
        });
        ## 企业管理 END

        ## 合同管理 ADD
        Route::group('contract', function () {
            Route::group('basic', function () {
                Route::get('getContractList', '/contractList');
                Route::post('addContract', '/addContract');
                Route::put('editContract/:id', '/editContract');
                Route::delete('delete/:id', '/delete');
                Route::get('getDetail/:id', '/detail');##获取房源详情
                Route::get('getCode/:id', '/getCode');## 获取合同编号
                Route::get('getStatistics/:id', '/getStatistics');#### 合同统计
                Route::post('extendContract/:id', '/extendContract');#### 合同续租
                Route::post('auditContract/:id', '/auditContract');#### 合同审核
                Route::post('renunContract/:id', '/renunContract');#### 合同退租
                Route::post('invalidContract/:id', '/invalidContract');#### 合同作废
                Route::get('getVacancyList/:id', '/vacancyList');##获取空置房间
                Route::get('getBindRoomList/:id', '/bindRoomList');##获取关联房间
                Route::post('roomBound/:id', '/roomBound');## 合同 关联 房间
            })->prefix('api.contract.ContractBasic');
            Route::group('lessee', function () {
                Route::get('getLesseeList/:id', '/lesseelist');##
                Route::post('addLessee/:id', '/addLessee');##
                Route::put('editLessee/:id', '/editLessee');##
                Route::delete('delete/:id', '/delete');##
            })->prefix('api.contract.ContractLessee'); ## 同住人员
        })->middleware(\app\http\middleware\api\CheckToken::class, true);
        ## 合同管理 END

        ## 房间管理 ADD
        Route::group('room', function () {
            Route::group('basic', function () {
                Route::get('getVacancyList', '/vacancyList');##获取空置房间
                Route::group('', function () {
                    Route::get('getRoomList', '/roomList');
                    Route::post('addRoom', '/addRoom');
                    Route::put('editRoom/:id', '/editRoom');
                    Route::delete('delete/:id', '/delete');
                    Route::get('getDetail/:id', '/detail');##获取房源详情
                    Route::post('bindEnergyMeter/:id', '/bindEnergyMeter');##  绑定能源设备
                    Route::post('unbindEnergyMeter/:id', '/unbindEnergyMeter');## 解除能源设备
                    Route::get('getEnergyMeterList/:id', '/energyMeterList'); ## 根据房间 ID 查询设备列表
                })->middleware(\app\http\middleware\api\CheckToken::class, true); ## 楼栋单元
            })->prefix('api.room.RoomBasic');
        });
        ## 房间管理 END
        ## 账单管理 ADD
        Route::group('bill', function () {
            Route::group('cate', function () {
                Route::get('getCateList', '/cateList');##
            })->prefix('api.bill.BillCate'); ## 账单分类
            Route::group('basic', function () {
                Route::get('getStatistics/:id', '/getStatistics');## 账单统计
                Route::get('getBillList', '/getBillList');## 账单列表
                Route::post('addBill', '/addBill');
                Route::put('editBill/:id', '/editBill');
                Route::delete('delete/:id', '/delete');
                Route::get('getDetail/:id', '/detail');##获取账单详情
                Route::get('getBillCatalog/:id', '/billCatalog');##获取账单明细
                Route::post('postponeAdd/:id', '/postponeAdd');#### 账单延期
                Route::post('invalidAdd/:id', '/invalidAdd');#### 作废账单
                Route::post('urgeAdd/:id', '/urgeAdd');#### 催缴提醒
                Route::post('auditAdd/:id', '/auditAdd');#### 账单审核
                Route::post('paymentAdd/:id', '/paymentAdd');#### 确认收款
            })->prefix('api.bill.BillBasic')->middleware(\app\http\middleware\api\CheckToken::class, true);
            Route::group('catalog', function () {
                Route::post('paymentAdd/:id', '/paymentAdd');#### 确认收款
            })->prefix('api.bill.BillCatalog')->middleware(\app\http\middleware\api\CheckToken::class, true);
        });
        ## 账单管理 END
        ## 房源管理 ADD
        Route::group('housing', function () {
            Route::group('resource', function () {
                Route::get('getResourceList', '/resourceList');##获取房源列表
                Route::get('getDetail/:id', '/detail');##获取房源详情

                Route::group('', function () {
                    Route::post('makeAdd/:id', '/makeAdd'); ##预约看房
                })->middleware(\app\http\middleware\api\CheckToken::class, true);
            })->prefix('api.housing.HousingResource');
        });
        ## 房源管理 END
        ## 充电桩 ADD
        Route::group('piles', function () {
            Route::group('basic', function () {
                Route::get('getPilesList', '/pilesList');##获取充电桩列表
                Route::get('getDetail/:id', '/detail');##获取充电桩详情

                Route::group('', function () {
                    Route::get('startCharge/:id', '/startCharge'); ##开启充电
                })->middleware(\app\http\middleware\api\CheckToken::class, true);
            })->prefix('api.piles.PilesBasic');
        });
        ## 充电桩 END

    })->prefix('api.items.')->middleware(\app\http\middleware\api\CheckProperty::class, true);

    # miss路由
    Route::miss(function () {
        return \think\Response::create(['code' => 404, 'msg' => '接口不存在'], 'json')->code(404);
    });
};

if (env('MULTI_DOMAIN_MODE', false)) {
    Route::domain(env('API_URL'), $propertyApiRoute)
        ->prefix('api.')
        ->pattern(['id' => '[1-9]\d*'])
        ->middleware(\app\http\middleware\api\AllowCrossDomain::class);  // 独立域名访问
} else {
    Route::group(env('API_URL') ?: 'api', $propertyApiRoute)
        ->prefix('api.')
        ->pattern(['id' => '[1-9]\d*'])
        ->middleware(\app\http\middleware\api\AllowCrossDomain::class);  // 单域名访问
}
